Skip to content

xinetd probe: bound paths and strans keys; export oscap_path_join#2349

Draft
Mab879 wants to merge 1 commit into
OpenSCAP:mainfrom
Mab879:cursor/xinetd-probe-bounded-paths-and-strans
Draft

xinetd probe: bound paths and strans keys; export oscap_path_join#2349
Mab879 wants to merge 1 commit into
OpenSCAP:mainfrom
Mab879:cursor/xinetd-probe-bounded-paths-and-strans

Conversation

@Mab879

@Mab879 Mab879 commented May 4, 2026

Copy link
Copy Markdown
Member

Use snprintf and length checks for stack buffers; build includedir paths with oscap_path_join. Mark oscap_path_join OSCAP_API for embedded tests. Add regression test for oversized name+protocol key.

Fixes various code issues in this file.

@Mab879 Mab879 added this to the 1.4.5 milestone May 4, 2026
Comment thread src/OVAL/probes/unix/xinetd_probe.c Fixed
@Mab879 Mab879 marked this pull request as draft May 4, 2026 20:02
@Mab879 Mab879 marked this pull request as draft May 4, 2026 20:02
Comment thread src/common/util.h Outdated
* path by exactly 1 slash separator.
*/
char *oscap_path_join(const char *path1, const char *path2);
OSCAP_API char *oscap_path_join(const char *path1, const char *path2);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function prototypes marked with OSCAP_API need to be put in a public header file. Please move it for example to src/common/public/oscap.h.

@Mab879 Mab879 force-pushed the cursor/xinetd-probe-bounded-paths-and-strans branch 4 times, most recently from 474e82d to 3a6fadc Compare May 8, 2026 14:25
Use snprintf and length checks for stack buffers; build includedir paths
with oscap_path_join. Mark oscap_path_join OSCAP_API for embedded tests.
Add regression test for oversized name+protocol key.

Co-authored-by: Cursor <cursoragent@cursor.com>
@Mab879 Mab879 force-pushed the cursor/xinetd-probe-bounded-paths-and-strans branch from 3a6fadc to 9d2f7f0 Compare May 8, 2026 14:34
@sonarqubecloud

sonarqubecloud Bot commented May 8, 2026

Copy link
Copy Markdown

@Mab879 Mab879 marked this pull request as ready for review May 8, 2026 14:52
@Mab879 Mab879 marked this pull request as draft May 8, 2026 14:53
edznux-dd added a commit to edznux-dd/openscap that referenced this pull request Jun 12, 2026
Bugs found by fuzzing xiconf_parse()/xiconf_parse_section() with crafted
xinetd configuration content. A regression test exercising each case is
added in a follow-up commit (tests/probes/xinetd).

- A line with no trailing newline set the line length to the whole file
  length instead of the bytes remaining from the current offset, so the
  fixed line buffer was overflowed by memcpy() (heap-buffer-overflow). Two
  sites: the top-level scanner and xiconf_parse_section().
- An unterminated service section ran its for(;;) reader past the end of
  the in-memory file; bound the loop to inoff < inlen and guard the
  section entry against inoff already being at/after the end.
- *strchr(buffer, ' ') = '\0' dereferenced NULL when the copied line
  contained an embedded NUL (arbitrary file content), at two sites
  (keyword and service name). Check the result before writing.
- For a keyword with no value, op was set past the keyword's NUL
  terminator, reading out of bounds; only step past it when a value
  follows.
- A (name, protocol) translation key was built with strcpy()/strcat()
  into a fixed buffer with no NULL or length check; a NULL protocol
  dereferenced and an over-long name+protocol overflowed it. Guard both,
  matching the checks already in xiconf_getservice().
- xiconf_service_free() recursed over the ->next chain; a long crafted
  chain overflowed the stack. Free iteratively.
- On an unrecognized type value, scur->type (strdup'd, later free'd) was
  reassigned to a string literal -> invalid free, and the old value
  leaked. Free the old value and strdup("").
- op_assign_str() leaked the previous value when an attribute was
  repeated within a section; free before reassigning.

We are aware of the in-progress hardening in OpenSCAP#2349, which touches this
file; its scope (include-path handling) is narrower and does not cover
the bugs above. Two findings overlap and are reconciled here.
edznux-dd added a commit to edznux-dd/openscap that referenced this pull request Jun 12, 2026
Bugs found by fuzzing xiconf_parse()/xiconf_parse_section() with crafted
xinetd configuration content. A regression test exercising each case is
added in a follow-up commit (tests/probes/xinetd).

- A line with no trailing newline set the line length to the whole file
  length instead of the bytes remaining from the current offset, so the
  fixed line buffer was overflowed by memcpy() (heap-buffer-overflow). Two
  sites: the top-level scanner and xiconf_parse_section().
- An unterminated service section ran its for(;;) reader past the end of
  the in-memory file; bound the loop to inoff < inlen and guard the
  section entry against inoff already being at/after the end.
- *strchr(buffer, ' ') = '\0' dereferenced NULL when the copied line
  contained an embedded NUL (arbitrary file content), at two sites
  (keyword and service name). Check the result before writing.
- For a keyword with no value, op was set past the keyword's NUL
  terminator, reading out of bounds; only step past it when a value
  follows.
- A (name, protocol) translation key was built with strcpy()/strcat()
  into a fixed buffer with no NULL or length check; a NULL protocol
  dereferenced and an over-long name+protocol overflowed it. Guard both,
  matching the checks already in xiconf_getservice().
- xiconf_service_free() recursed over the ->next chain; a long crafted
  chain overflowed the stack. Free iteratively.
- On an unrecognized type value, scur->type (strdup'd, later free'd) was
  reassigned to a string literal -> invalid free, and the old value
  leaked. Free the old value and strdup("").
- op_assign_str() leaked the previous value when an attribute was
  repeated within a section; free before reassigning.

We are aware of the in-progress hardening in OpenSCAP#2349, which touches this
file; its scope (include-path handling) is narrower and does not cover
the bugs above. Two findings overlap and are reconciled here.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants